package com.feige.controller;


import com.feige.constant.Constants;
import com.feige.pojo.Swiper;
import com.feige.result.AjaxResult;
import com.feige.service.SwiperService;
import com.feige.utils.redis.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author feige
 * @since 2021-05-09
 */
@Api(tags = "轮播图控制器")
@RestController
@RequestMapping("/course/swiper")
public class SwiperController {

    @Autowired
    private SwiperService swiperService;

    @Autowired
    private RedisUtils redisUtils;


    @ApiOperation("获取轮播图")
    @GetMapping("/get")
    public AjaxResult getSwiper(){
        List<Object> objects = redisUtils.lGet(Constants.SWIPER_KEY, 0, -1);
        if (objects != null && !objects.isEmpty()){
            return AjaxResult.success(objects.get(0));
        }else {
            List<Swiper> list = swiperService.list(null);
            redisUtils.lSet(Constants.SWIPER_KEY,list);
            return AjaxResult.success(list);
        }
    }
}

